/*********************************************************************************
* Copyright (c) zhujinyang.
* All rights reserved.
*
* \file
*
* os error handle
*
* 
*********************************************************************************/
#include "string.h"
#include "os_ext_api.h"

/*
********************************************************************************
* define config parameters
********************************************************************************
*/


/*
********************************************************************************
* define struct
********************************************************************************
*/



/*
********************************************************************************
* define module variants
********************************************************************************
*/
static void (*s_err_handler[1])(char *filename, INT32U line);



/**********************************************************************************
* \brief:       handle assert callback
* \param[in]:   filename:  assert file name
* \param[in]:   line:  the line of assert
* \return:      none
**********************************************************************************/
void cc_error(char *filename, INT32U line)
{
    INT32U i, len;

    len = strlen(filename);
    for (i = len; i > 0; i--) {
        if (filename[i - 1] == '/') {
            break;
        }
    }
    filename += i;
    len -= i;

    for (i = 0; i < sizeof(s_err_handler)/sizeof(s_err_handler[0]); i++) {
        if (s_err_handler[i] != 0) {
            s_err_handler[i](filename, line);
        }
    }

    for (; ;);
}



/**********************************************************************************
* \brief:       register assert hanlde callback
* \param[in]:   hanlder:  callback function
* \return:      0 : success, -1 : failure
**********************************************************************************/
INT32S cc_error_register_handler(void (*handler)(char *filename, INT32U line))
{
    INT32U  i;

    for (i = 0; i < sizeof(s_err_handler)/sizeof(s_err_handler[0]); i++) {
        if (s_err_handler[i] == 0) {
            s_err_handler[i] = handler;
            return 0;
        }
    }

    return -1;
}



